package org.lanqiao.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.Session;

import org.lanqiao.bean.EduUserBean;
import org.lanqiao.myUtils.Myutils;
import org.lanqiao.service.FactoryService;

public class StuQuerySelfInfoSevelet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse Response)
			throws ServletException, IOException {
		int stuInfo = Myutils.getInt(request.getParameter("stuInfo"));
		if (stuInfo == 1) {
			// 修改学生的sevelet
			EduUserBean eub = (EduUserBean) Myutils.getNewInstance(EduUserBean.class);
			eub.setUserid(Myutils.getInteger(request.getParameter("userId")));
			eub.setUsername(request.getParameter("userName"));
			eub.setUserpassword(request.getParameter("userPassword"));
			eub.setUserage(Myutils.getInteger(request.getParameter("userAge")));
			eub.setUsersex(request.getParameter("userSex"));
			eub.setUsertel(request.getParameter("userTel"));
			eub.setUseradress(request.getParameter("userAddress"));
			EduUserBean eub1 = FactoryService.getUserInfoManageService().updateStudentInfo(eub);
			request.getSession().setAttribute("StudentInfo", eub1);
			
			

			request.getRequestDispatcher("logined/stuLoginedInfo/querySelfInfo.jsp").forward(request, Response);
		} else if (stuInfo == 2) {
			// 把添加的课程信息接收并添加
			String couseId = request.getParameter("uid");

			String stuName=(String) request.getSession().getAttribute("username");

			List stuCouAll = FactoryService.getUserInfoManageService().getStuAllC(couseId, stuName);
			
			request.getSession().setAttribute("StuCourSel", stuCouAll);
			
			List stucourse=FactoryService.getUserInfoManageService().getStuCoIn(stuName);

			request.getSession().setAttribute("stucourse", stucourse);

			request.getRequestDispatcher("logined/stuLoginedInfo/StuSelectCourse.jsp").forward(request, Response);

		}
	}

}
